using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

namespace PocketSettings
{
    /// <summary>
    /// Class for storing application settings in a xml file
    /// </summary>
    public class Settings
    {
        private Dictionary<string, string> _settings = new Dictionary<string, string>(20);

        public Dictionary<string, string> SettingDictionary
        {
            get
            {
                return _settings;
            }
            set
            {
                _settings = value;
            }
        }

        public ValueStatus Add(string setting)
        {
            if (SettingDictionary.ContainsKey(setting))
            {
                SettingDictionary[setting] = string.Empty;
                return ValueStatus.ValueUpdated;
            }
            else
            {
                SettingDictionary.Add(setting, string.Empty);
                return ValueStatus.ValueAdded;
            }
        }

        public ValueStatus Add(string setting, string value)
        {
            if (SettingDictionary.ContainsKey(setting))
            {

                SettingDictionary[setting] = value;
                return ValueStatus.ValueUpdated;
            }
            else
            {
                SettingDictionary.Add(setting, value);
                return ValueStatus.ValueAdded;
            }
        }

        public string Get(string setting)
        {
            if (SettingDictionary.ContainsKey(setting))
                return SettingDictionary[setting];
            else
                return string.Empty;
        }

        public ValueStatus Update(string key, string value)
        {
            if (SettingDictionary.ContainsKey(key))
            {
                SettingDictionary[key] = value;
                return ValueStatus.ValueUpdated;
            }
            else
                return ValueStatus.ValueMissing;
        }
    }
}
